package com.smartlib.cmnObject.dialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.smartlib.cmnObject.R;
import com.smartlib.cmnObject.util.DeviceUtil;
/**
 * Created by admin on 16/8/16.
 */
public class FileUploadDialogFragment extends DialogFragment implements View.OnClickListener {
    private Dialog dialog;
    private DialogOnClick<String> mCarmerOnClick, mAlbumOnClick;
    private TextView mTvCancel, mTvCarmer, mTvAlbum;
    private String mCarmer,mAlbum;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if(bundle!=null)
        {
            if(bundle.containsKey("carmer"))
            {
                mCarmer = bundle.getString("carmer");
            }
            if(bundle.containsKey("album"))
            {
                mAlbum = bundle.getString("album");
            }
        }
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        dialog = new Dialog(getActivity(), R.style.customdialog);
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.dialog_file_upload, null);
        dialog.setContentView(view);
        Window window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = DeviceUtil.getWidth(getActivity());
        window.setAttributes(lp);
        initView(view);
        return dialog;
    }
    private void initView(View view) {
        mTvCancel = (TextView) view.findViewById(R.id.update_tv_cancel);
        mTvCarmer = (TextView) view.findViewById(R.id.update_tv_camera);
        mTvAlbum = (TextView) view.findViewById(R.id.update_tv_from_album);
        if(!TextUtils.isEmpty(mCarmer)){
            mTvCarmer.setText(mCarmer);
        }
        if(!TextUtils.isEmpty(mAlbum))
        {
            mTvAlbum.setText(mAlbum);
        }



        mTvCancel.setOnClickListener(this);
        mTvCarmer.setOnClickListener(this);
        mTvAlbum.setOnClickListener(this);
    }
    public void setOnClick(DialogOnClick<String> onClickCarmer,DialogOnClick<String> onClickAlbum) {
        this.mCarmerOnClick = onClickCarmer;
        this.mAlbumOnClick = onClickAlbum;
    }
    //
//
    @Override
    public void onClick(View v) {
        if (v == mTvCancel) {
            dialog.dismiss();
        } else if (v == mTvCarmer) {
            if (mCarmerOnClick != null) {
                mCarmerOnClick.onClick(null);
            }
            dialog.dismiss();
        } else if (v == mTvAlbum) {
            if (mAlbumOnClick != null) {
                mAlbumOnClick.onClick(null);
            }
            dialog.dismiss();
        }
    }
}